﻿using UnityEngine;
using UnityEngine.UI;

// 拼图类
public class Piece : MonoBehaviour {
    // public.
    // 删除flag
    public bool deleteFlag;

    // private.
    private Image thisImage;
    private RectTransform thisRectTransform;

    // 种类
    private PieceKind kind;

    //-------------------------------------------------------
    // MonoBehaviour Function
    //-------------------------------------------------------
    // 初始化处理
    private void Awake ( ) {
        // 获取装载中的各个组件
        thisImage = GetComponent<Image> ( );
        thisRectTransform = GetComponent<RectTransform> ( );

        // 初始化flag
        deleteFlag = false;
    }

    //-------------------------------------------------------
    // Public Function
    //-------------------------------------------------------
    // 设置拼图的种类，根据种类设定颜色
    public void SetKind (PieceKind pieceKind) {
        kind = pieceKind;
        SetColor ( );
    }

    // 返回拼图的种类
    public PieceKind GetKind ( ) {
        return kind;
    }

    // 设置拼图的大小
    public void SetSize (int size) {
        this.thisRectTransform.sizeDelta = Vector2.one * size;
    }

    //-------------------------------------------------------
    // Private Function
    //-------------------------------------------------------
    // 拼图的颜色根据种类进行设定
    private void SetColor ( ) {
        switch (kind) {
        case PieceKind.Red:
            thisImage.color = Color.red;
            break;
        case PieceKind.Blue:
            thisImage.color = Color.blue;
            break;
        case PieceKind.Green:
            thisImage.color = Color.green;
            break;
        case PieceKind.Yellow:
            thisImage.color = Color.yellow;
            break;
        case PieceKind.Black:
            thisImage.color = Color.black;
            break;
        case PieceKind.Magenta:
            thisImage.color = Color.magenta;
            break;
        default:
            break;
        }
    }

    // 拼图修改透明度
    public void SetPieceAlpha (float alpha) {
        var col = thisImage.color;
        col.a = alpha;
        thisImage.color = col;
    }
}
